<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Newscategory extends MY_Luckydog {
    public function __construct()
    {

        parent::__construct();
        $this->load->model('luckydog/newscategory_model', 'cat');
    }
	public function index()
	{
        $_SESSION['v_menu'] = 'newsCategory';
        $result = $this->cat->get_cat_list();
        $data=array(
            'cat_list'=>$result,
        );

		$this->load->view('luckydog/news/category_list',$data);
	}
    //添加分类 html
	public function add()
	{
		$this->load->view('luckydog/news/category_add');
	}
    //修改分类 html
	public function edit()
	{
        $id  = $this->input->get("id");
	    if (empty($id)){
            show_message("参数错误~, <a class='poi' onclick='javascript:history.go(-1);'>返回>></a>");
            exit;
	    }
        $cat_row = $this->cat->get_cat_by_id($id);
        $data=array(
            'cat_row'=>$cat_row
        );
		$this->load->view('luckydog/news/category_edit',$data);
	}
    public function do_add(){
        $cat_name   = $this->input->post("cat_name");
        $sort_order = $this->input->post("sort_order");
        $data = array(
            "cat_name"=>$cat_name,
            "sort_order"=>$sort_order,
        );

        $insert_id = $this->cat->add_cat($data);
        if($insert_id){
            echo json_encode(array('status'=>1,'message'=>'添加分类成功'));
        }else{
            echo json_encode(array('status'=>-1,'message'=>'添加分类失败'));
        }
        exit;
    }
    public function do_edit(){
        $cat_id   = $this->input->post("cat_id");
        $cat_name   = $this->input->post("cat_name");
        $sort_order = $this->input->post("sort_order");

        $data = array(
            "cat_name"=>$cat_name,
            "sort_order"=>$sort_order,
        );
        $edit_flag = $this->cat->edit_cat($cat_id,$data);

        if($edit_flag){
            echo json_encode(array('status'=>1,'message'=>'修改分类成功'));
        }else{
            echo json_encode(array('status'=>-1,'message'=>'修改分类失败'));
        }
        exit;
    }
    public function do_del(){
        $cat_id  = $this->input->post("cat_id");
        $this->cat->del_cat($cat_id);
        echo json_encode(array('status'=>1));
        exit;
    }
}

/* End of file category.php */
/* Location: ./application/controllers/luckydog/category.php */